<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/1/6/006
 * Time: 20:28
 */

namespace app\api\controller\v1;


use app\api\controller\BaseController;
use app\api\model\Collect as CollectMode;
use app\api\validate\IDMustBePostiveInt;
use app\lib\exception\SuccessMessage;

class Collect extends BaseController {

    /**
     * 获取用户收藏列表
     * @return \think\Paginator
     */
    public function collectList() {
        return CollectMode::collectList();
    }

    /**
     * 收藏商品
     * @param $id
     * @return \think\response\Json
     */
    public function addCollect($id) {
        (new IDMustBePostiveInt())->goCheck();

        CollectMode::addCollect($id);

        return json(new SuccessMessage(), 201);
    }

    /**
     * 删除收藏
     * @return \think\response\Json
     */
    public function deleteCollect() {
        (new IDMustBePostiveInt())->goCheck();
        $id = input('param.id');
        CollectMode::deleteCollect($id);
        return json(new SuccessMessage(), 201);
    }

    /**
     * 检查是否有收藏
     * @param $id
     * @return array
     */
    public function checkCollect($id) {
        (new IDMustBePostiveInt())->goCheck();

        return CollectMode::checkCollect($id);
    }
}